package day6.volatile_demo;

import java.util.concurrent.TimeUnit;
/**
 * volatile修饰变量,保证内存可见性
 */
public class WithOutVolatile {

    volatile static boolean quit = false;

    static class MyThread extends Thread {
        @Override
        public void run() {
            long r = 0;
            while (quit == false) {
                r++;
            }
            // while结束后输出
            System.out.println(r);
        }
    }

    public static void main(String[] args) throws InterruptedException {

        MyThread t = new MyThread();
        t.start();

        TimeUnit.SECONDS.sleep(3);
        quit = true;
    }
}
